#include "single_list.h"

void list_del(struct list *head,struct list *delete)
{
    struct list *pTmp = head->next;
    struct list *prev = head;

    for(;pTmp != delete;prev = pTmp,pTmp = pTmp->next);

    if(pTmp == delete)
    {
        prev->next = prev->next->next;
    }
}

void list_add_head(struct list *head,struct list *insert)
{
    insert->next = head->next;
    head->next = insert;
}

void list_del_head(struct list *head)
{
    head->next = head->next->next;
}

void list_add_tail(struct list *head,struct list *insert)
{
    struct list *pTmp = head;

    for(;pTmp->next;pTmp = pTmp->next);

    pTmp->next = insert;
    insert->next = NULL;
}

void list_del_tail(struct list *head)
{
    struct list *pTmp = head->next;
    struct list *prev = head;

    for(;pTmp && pTmp->next;prev = pTmp,pTmp = pTmp->next);

    prev->next = NULL;
}

bool list_is_empty(struct list *head)
{
    return head->next == NULL;
}
